<%@page import="java.text.SimpleDateFormat"%>
<%@page import="javax.lang.model.util.SimpleAnnotationValueVisitor6"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@page import="org.nado.bbs.*, java.util.Date, java.util.List"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<%
	request.setCharacterEncoding("UTF-8");
%>
<base href="../resources/" />
<meta http-equiv="content-type" content="text/html; charset= UTF-8" />
<title>nonzero1.0 by nodethirtythree</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="style/style.css" />

<style type="text/css">
table {
	width: 500px;
	border-collapse: collapse;
	text-align: center;
	font-family: 'Trebuchet MS';
}

td,th {
	font-size: 10pt;
	border: 1px solid #ffffff;
	height: 30px;
}

th {
	background-color: #aaaaaa;
	color: #ffffff;
	font-family: Georgia;
}

tr.alt td {
	color: #111111;
	background-color: #dcdcdc;
}
</style>
<script>
	function remove() {
		if (confirm('안녕하십니까?')) {
			alert("${content.bbs_no}");
			// 			location.href="/web/bbs/list?page_no=${page_no}";
			location.href = "/web/bbs/remove?bbs_no=${content.bbs_no}";
		}
	}
</script>
</head>
<body>
	<div id="header">

		<%@ include file="../common/board_header.jspf"%>
	</div>

	<div id="main">

		<div id="main_inner" class="fixed">

			<div id="primaryContent_2columns">

				<div id="columnA_2columns">

					<H3>Read</H3>
					<p>
					<table>
						<tr>
							<th>글번호</th>
							<th>제목</th>
							<th>작성자</th>
							<th>작성일</th>
							<th>조회수</th>
						</tr>
						<tr>

							<td>${content.bbs_no}</td>
							<td>${content.bbs_title}</td>
							<td>${content.bbs_writer}</td>
							<td><c:set var="date" value="${content.bbs_regDate}" /> <fmt:formatDate
									value="${date}" pattern="yyyy/MM/dd" /></td>
							<td>${content.bbs_readcnt}</td>
						</tr>
					</table>
					<table>
						<tr>
							<th>글내용</th>
						</tr>
						<tr>
							<td>${content.bbs_content}</td>
						</tr>
					</table>
					<br>

					<table>
						<tr>
							<%
								BBSBoardVO bbs = (BBSBoardVO) session.getAttribute("content");
								if (session.getAttribute("loginInfo") == null
										|| session.getAttribute("loginInfo") == "") {
								} else {
									MemberVO login = (MemberVO) session.getAttribute("loginInfo");
									String loginID = login.getMem_id();
									String requestID = bbs.getBbs_writer();
									if (loginID.equals(requestID)) {
							%>
							<td style="text-align: left">
								<!-- 								<form id="remove" style='display:inline' method="post"> -->
								<input type="button" onclick="remove()" value="삭제하기"></input> <!-- 								</form> -->
								<form style='display: inline'
									action="/web/bbs/modify?bbs_No=${content.bbs_no}" method="post">
									<input type="submit" value="수정하기"></input>
								</form>
							</td>
							<%
								}
								}
							%>
							<td style="text-align: right">
								<form style='display: inline'
									action="/web/bbs/write?bbs_no=${content.bbs_no}" method="post">
									<input type="submit" value="답글쓰기"></input>
								</form> <a href="javascript:history.back()"> <%--  								<a href="/web/bbs/list?page_no=${page_no}">  --%>
									<input type="button" value="뒤로가기"> </input></a>

							</td>
						</tr>
					</table>
					<button id='showReply'>댓글보기</button><br>
					
					<c:choose>
						<c:when test="${sessionScope['loginInfo']==null}">
								로그인을 해야 댓글 작성이 가능합니다.
						</c:when>
						<c:otherwise>
								<form action="/web/bbs/addReply" method="post">
									<input type="hidden" name="rep_id" value='${loginInfo.mem_id}'>
									<input type="hidden" name="bbs_rep_no" value='${content.bbs_no}'>
									<input type="text" name="rep_content" size="40">
									<input type="submit" value="댓글달기" /><input type="reset" value="다시작성" />
								</form>
						</c:otherwise>
					</c:choose>
					<div id="replys">
					</div>
					<script type="text/javascript"
						src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
					</script>
					<script>
						
					
						var bbs_rep_no = ${content.bbs_no};
						$("#showReply").toggle(
						function(){
							console.log("aaa");
							$.getJSON("/web/bbs/getReply/"+bbs_rep_no+".json", function(data){
								
								var str="";
								
							
									
								$(data).each(function(idx){
									console.log(this.rep_no);
									console.log(this.rep_content);
									console.log(this.rep_id);
									console.log(this.rep_date);
									str +="<table border = '2' bordercolor = black width= 500px><tr>"
											+"<td width=50px>"+ this.rep_no +"</td>" 
											+"<td width=300px>"+ this.rep_content +"</td> " 
											+"<td width = 50px>"+ this.rep_id +"</td>"
											+"<td width = 50px>"+ this.rep_date+"</td>";
									if(this.rep_id == '${loginInfo.mem_id}'){
									str +="<td width = 50px>"
												+"<form action='/web/bbs/removeReply' method='post'>"
												+"<input type='hidden' name='bbs_rep_no' value='${content.bbs_no}'>"
												+"<input type='hidden' name='rep_no' value="+this.rep_no+">"
												+"<input type='submit' value='삭제하기'></input></form>"+"</td>";
												console.log("삭제 가능");}
									str+="</tr></table>";  
									});
								$("#replys").html(str);
								 $("#showReply").text("댓글 감추기");
							});
							}, function(){
								var str = "";
								 $("#replys").html(str);
								 $("#showReply").text("댓글 보기");
								 
								 
							});
					</script>
					
					

					<br> <br> <br>

					<%-- 					<table>
						<tr>
							<th>댓글 내용</th>
							<th>작성자</th>
							<th>작성일자</th>
						</tr>


						<%List <ReplyVO> replyList = (List<ReplyVO>)request.getAttribute("replyList"); 
							for(int i= 0; i <replyList.size(); i++){
								String re_content = (String)replyList.get(i).getRe_content();
								String re_id = (String)replyList.get(i).getRe_id();
								Date re_repdate = (Date)replyList.get(i).getRe_date();
								SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
								String re_date = format.format(re_repdate);
								String re_no = (String)replyList.get(i).getRe_no();
						
								%>
								<tr>
									<td><%=re_content %></td>
									<td><%=re_id %></td>
									<td><%=re_date %></td>
									<td>	<%if (session.getAttribute("MemberVO") == null || session.getAttribute("MemberVO") == "") {%>
									<%} else {
									MemberVO vo1 = (MemberVO) session.getAttribute("MemberVO");
									String loginID = vo1.getMem_id();%>
									<%;
									if (loginID.equals(re_id) ) {%>
									<form action="/bbs.do?method=deleteReply" method="post">
									<input type="hidden" name="bbs_No"	value=<%=bbs_No%>>
									<input type="hidden" name="re_no"	value=<%=re_no %>> <input
										type="submit" value="삭제하기" />
								</form><%}}%>
									</td>
								</tr>
								<%}%>
					</table>

					<br>
					<%
						if (session.getAttribute("MemberVO") == null	|| session.getAttribute("MemberVO") == "") {
					%>
					로그인 후 댓글 입력이 가능합니다.
					<%
						} else {
					%>
					댓글을 입력해주세요
					<form action="/bbs.do?method=addReply"
						method="post">
						<input type="hidden" name="re_id" value=${MemberVO.mem_id}>
						<input type="hidden" name="bbs_No" value=<%=bbs_No%>>
						<input type="text" name="re_content" size="40">
						<input type="submit" value="댓글달기" /><input type="reset" value="다시작성" />
					</form>
					<% }%>
 --%>
					<br>
					</p>

					<br> <br class="clear" />

				</div>

			</div>

		</div>

	</div>

	<div id="aside">
		<%@include file="../common/sider.jspf"%>
	</div>
	<div id="footer" class="fixed">
		<%@include file="../common/footer.jspf"%>
	</div>
</body>
</html>